import SDKBase from "./SDKBase";
import { SDKState } from "../SDKDefine";
export default class SDKLogin extends SDKBase {
    checkSession(callback: (r: number) => void) {
        this.sdk.checkSession({
            success(res: any) {
                console.log(`session未过期`);
                callback(SDKState.SUCCESS);
            },
            fail(res: any) {
                console.log(`session已过期，需要重新登录`);
                callback(SDKState.FAIL);
            }
        });
    }


    login(account: string, func: (r: number, data: any) => void) {
        let isForce: boolean = false;
        let info = this.sdk.getSystemInfoSync();
        console.log(' login == info ', info)
        if (info.appName == 'Douyin') {
            isForce = true;
        }
        this.sdk.login({
            force: isForce,
            success(res: any) {
                console.log(`login调用成功${res.code} ${res.anonymousCode}`);
                func(SDKState.SUCCESS, res)
            },
            fail(res: any) {
                // console.log(`login调用失败`);
                if (isForce) {
                    func(SDKState.FAIL, null)
                } else {
                    func(SDKState.SUCCESS, null)
                }

            }
        });

    }

    getUserInfo(withCredentials: string, lang: string, func: (r: number, data: any) => void) {
        this.sdk.getUserInfo({
            withCredentials: withCredentials,
            lang: lang,
            success(res: any) {
                console.log(`getUserInfo调用成功${res.userInfo}`);
                func(SDKState.SUCCESS, res)
            },
            fail(res: any) {
                console.log(`getUserInfo调用失败`, res);
                func(SDKState.FAIL, null)
            }
        });
    }


    logout() {

    }
}
